﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;

namespace DMU.Gui.GuiPro
{
    public partial class frmChuyenDoiThongTin : DevExpress.XtraEditors.XtraForm
    {
        help hp = new help();
        Service sv = new Service();
        public frmChuyenDoiThongTin()
        {
            InitializeComponent();
        }

        private void lkpLop_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if (lkpLop.Text.Trim()!= "")
                {
                    DataTable dt = sv.getDatatable("dmu_proPublicFindLop", new SqlParameter("name", lkpLop.Text+"%"));
                    lkpLop.Properties.DataSource = dt;
                    lkpLop.Properties.ValueMember = "MaLop";
                    lkpLop.Properties.DisplayMember = "TenLop";
                }

            }
        }

        private void lkpMonHoc_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if (lkpMonHoc.Text.Trim()!= "")
                {
                    DataTable dt = sv.getDatatable("dmu_proPublicFindMonHoc", new SqlParameter("name", lkpMonHoc.Text + "%"));
                    lkpMonHoc.Properties.DataSource = dt;
                    lkpMonHoc.Properties.ValueMember = "MaMH";
                    lkpMonHoc.Properties.DisplayMember = "TenMH";
                }

            }

        }

        private void btnLoadData_Click(object sender, EventArgs e)
        {
            
            if(lkpMonHoc.EditValue==null)
            {
               lkpMonHoc.Focus();
                return;
            }
            if(lkpLop.EditValue==null)
            {
                lkpLop.Focus();
                return;
            }

            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter("Ngay0", string.Format("{0:yy/MM/dd}", dteNgay.DateTime));
            pr[1] = new SqlParameter("MaLop0",lkpLop.EditValue.ToString());
            pr[2] = new SqlParameter("MaMH0",lkpMonHoc.EditValue.ToString());

            DataTable dt= sv.getDatatable("dmu_proChuyenDoiFind", pr);
            gridControl1.DataSource = dt;

        }

        private void gridView3_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            if (e.IsGetData)
                e.Value = e.ListSourceRowIndex + 1;
        }

        private void btnChuyenDoi_Click(object sender, EventArgs e)
        {
            int rowHandle=gridView3.FocusedRowHandle;
            if (rowHandle >= 0)
            {
                frmChuyenDoi frm = new frmChuyenDoi(this);
                frm.txtMaTKB.Text = gridView3.GetRowCellValue(rowHandle, "MaTKB").ToString();
                frm.txtPhong.Text = gridView3.GetRowCellValue(rowHandle, "MaPhong").ToString();
                frm.dteNgay.Text = gridView3.GetRowCellValue(rowHandle, "Ngay").ToString();
                frm.txtTietBD.Text = gridView3.GetRowCellValue(rowHandle, "TietBD").ToString();
                frm.ShowDialog();
            }
        }

        private void frmChuyenDoiThongTin_Load(object sender, EventArgs e)
        {

        }

        private void đổiThôngTinToolStripMenuItem_Click(object sender, EventArgs e)
        {
            btnChuyenDoi_Click(sender, e);
        }
    }
}